/**
 *                      Copyright 2025 walter
 * <p>
 *      Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 *              http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 *      Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.walter.gitee.integration;

import cn.hutool.core.util.StrUtil;
import com.walter.gitee.configuration.GiteeProperties;
import com.walter.gitee.service.APIService;
import com.walter.gitee.service.OAuthService;
import org.noear.solon.Solon;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GiteePlugin implements Plugin {

    static Logger log = LoggerFactory.getLogger(GiteePlugin.class);

    @Override
    public void start(AppContext context) throws Throwable {

        if (StrUtil.isBlank(Solon.cfg().get("solon.gitee.clientId"))
                || StrUtil.isBlank(Solon.cfg().get("solon.gitee.clientSecret"))
                || StrUtil.isBlank(Solon.cfg().get("solon.gitee.redirectUri"))) {
            log.error("[GiteePlugin] Please configure solon.gitee.clientId and solon.gitee.clientSecret and solon.gitee.redirectUri");
            return;
        }

        context.beanMake(GiteeProperties.class);
        context.beanMake(OAuthService.class);
        context.beanMake(APIService.class);
        log.info("[GiteePlugin] loaded");
    }
}
